const oldArrayPrototype = Array.prototype
export let arrayMethods = Object.create(oldArrayPrototype)

const methods = ['push','pop','unshift','shift','reverse','sort','splice']

methods.forEach((method)=>{
    arrayMethods[method] = function(...args){
         console.log('调用数组方法')
         oldArrayPrototype[method].call(this,...args)
         let inserted = null
         switch(method){
            case 'push':
            case 'unshift':
                inserted = args;
                break;
            case 'splice':
                inserted = args.slice(2)
                break
         }

         let ob = this.__ob__
         if(inserted){
            ob.observeArray(inserted)
         }
         ob.dep.notify()
    }
})